package com.ruoyi.web.controller.rjgc;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.littleRedBook.domain.pojo.Favorite;
import com.ruoyi.littleRedBook.service.FavoriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/favorite")
@Api(tags = "商品收藏管理")
public class FavoriteController {

    @Autowired
    private FavoriteService favoriteService;

    @PostMapping("/add/{productId}")
    @ApiOperation("收藏商品")
    public AjaxResult addFavorite(@ApiParam("商品ID") @PathVariable Long productId) {
        return favoriteService.addFavorite(productId);
    }

    @DeleteMapping("/remove/{productId}")
    @ApiOperation("取消收藏商品")
    public AjaxResult removeFavorite(@ApiParam("商品ID") @PathVariable Long productId) {
        return favoriteService.removeFavorite(productId);
    }

    @GetMapping("/my/list")
    @ApiOperation("获取当前用户的收藏商品列表")
    public AjaxResult getMyFavoriteList(
            @ApiParam("页码，默认1") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数，默认10") @RequestParam(defaultValue = "10") Integer pageSize) {
        return favoriteService.getMyFavoriteList(pageNum, pageSize);
    }

    @GetMapping("/check/{productId}")
    @ApiOperation("检查商品是否已收藏")
    public AjaxResult checkFavorite(@ApiParam("商品ID") @PathVariable Long productId) {
        return favoriteService.checkFavorite(productId);
    }
}
